package com.sundablog.controller.systemsetup.basicsetup.upload;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import javax.imageio.ImageIO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.sundablog.result.BaseResult;
import com.sundablog.service.systemsetup.basicsetup.upload.UploadService;

import cn.hutool.core.util.ImageUtil;
import cn.hutool.core.util.RandomUtil;

@Controller
public class UploadController {

	@Autowired
	private UploadService uploadService;

	/**
	 * layui文件上传
	 * @Title: layuiUpload   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param file
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/layuiUpload")
	@ResponseBody
	public BaseResult layuiUpload(MultipartFile file){
		BufferedImage read = null;
		try {
			read = ImageIO.read(file.getInputStream());
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		int width = read.getWidth();
		int height = read.getHeight();
		if (width >= 300 && height >= 300) {
			return BaseResult.build(201, "上传图片尺寸太大,(300*300)");
		}
		Map<String, String> map = null;
		try {
			map = uploadService.fileUploadLayui(file.getBytes(),RandomUtil.simpleUUID());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return BaseResult.build(200, "", map);
	}
	
	
	
	
}
